BIN2C = ../../../bin2char.sh

CROSS_COMPILE ?= arm-none-eabi-

CC=$(CROSS_COMPILE)gcc
OBJCOPY=$(CROSS_COMPILE)objcopy
OBJDUMP=$(CROSS_COMPILE)objdump


AFLAGS = -static -nostartfiles -mlittle-endian -Wa,-EL
CFLAGS = -c -mthumb -nostdlib -nostartfiles -Os -g -fPIC

all: ch32f103_flash.inc



%.elf: %.S
	$(CC) $(AFLAGS) $< -o $@

ch32f103_flash.elf: ch32f103_flash.c
	$(CC) $(CFLAGS) -mcpu=cortex-m3 -fstack-usage -Wa,-adhln=$(<:.c=.lst) $< -o $@
	$(OBJDUMP) -S $@ > asm.txt

%.lst: %.elf ch32f103_flash.c
	$(OBJDUMP) -S $< > $@

%.bin: %.elf ch32f103_flash.c
	$(OBJCOPY) -O binary $< $@

%.inc: %.bin ch32f103_flash.c
	$(BIN2C) < $< > $@

clean:
	-rm -f *.elf *.lst *.bin *.inc
.PHONY: %elf %.inc %.bin all clean